<template>
	<div class="container">
		<div class="jx-container">
      <el-form ref="form" :model="params_list" :rules="rules" label-width="130px" class="jx-form">
        <div class="jx-detail">
          <div class="detail-item">
            <div class="item_2">
              <div class="title">
                客户信息
              </div>
              <el-form-item label="客户姓名：" prop="name">
                <el-input v-model="params_list.name" placeholder="请输入客户姓名">
                </el-input>
              </el-form-item>
              <el-form-item label="客户手机号：" prop="tel">
                <el-input v-model="params_list.tel" placeholder="请输入商户手机号">
                </el-input>
              </el-form-item>
              <!-- <el-form-item label="车牌号：" prop="cpno">
                <el-input v-model="params_list.cpno" placeholder="请输入车牌号">
                </el-input>
              </el-form-item> -->
              <el-form-item label="订单类型：" prop="type">
                <el-select class="tel-value" v-model="params_list.type" placeholder="请选择">
                  <el-option label="赠送" value="1"></el-option>
                  <el-option label="其他" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="开始时间：" prop="start">
                <el-date-picker
                  v-model="params_list.start"
                  type="datetime"
                  placeholder="选择日期时间">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="结束时间：" prop="end">
                <el-date-picker
                  v-model="params_list.end"
                  type="datetime"
                  placeholder="选择日期时间">
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="item_2">
              <div class="title">
                保单信息
              </div>
              <el-form-item label="保险类型：" prop="bxtype">
                <el-select class="tel-value" v-model="params_list.type" multiple placeholder="请选择">
                  <el-option label="交强险" value="1"></el-option>
                  <el-option label="商业险" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="交强险单号：" prop="no">
                <el-input v-model="params_list.no" placeholder="请输入交强险单号"></el-input>
              </el-form-item>
              <el-form-item label="商业险单号：" prop="syno">
                <el-input v-model="params_list.syno" placeholder="请输入商业险单号"></el-input>
              </el-form-item>
            </div>
          </div>
        </div> 
        <div class="jx-detail">
          <div class="detail-item">
            <div class="item">
              <div class="title">
                产品信息
              </div>
              <div class="jx-table" style="padding-top: 0;">
                <div class="title" style="margin-bottom: 0;">
                  <span style="color: #999;font-size: 14px;font-weight: 500;">产品模板：</span>
                  <el-select class="tel-value" v-model="params_adres.name" placeholder="请选择" style="display: inline-block;width: 29%;">
                    <el-option label="不适用模板" value="1"></el-option>
                    <el-option label="自定义模板1" value="2"></el-option>
                    <el-option label="自定义模板2" value="3"></el-option>
                  </el-select>
                  <div class="add-new">
                    <el-button class="jx-btn" type="primary" @click="viewRow">添加产品</el-button>
                  </div>
                </div>
                <el-table :data="detail" border show-summary :summary-method="getSum" style="width: 100%" v-loading="boo.loading">
                  <el-table-column type="index" label="序列" width="60" align="center">
                    <template slot-scope="scope">
                      <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="item1" label="选择产品" align="center" :show-overflow-tooltip="true">
                    <!-- <template slot-scope="scope">
                      <span v-if="scope.row.item1">{{scope.row.item1 || ''}}</span>
                      <el-button v-else @click="viewRow(scope.row)" type="text" size="small">添加产品</el-button>
                    </template> -->
                  </el-table-column>
                  <el-table-column prop="item2" label="配置清单" align="center" :show-overflow-tooltip="true">
                  </el-table-column>
                  <el-table-column prop="item3" label="适用地区" align="center" :show-overflow-tooltip="true">
                  </el-table-column>
                  <el-table-column prop="item2" label="产品数量" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span v-if="scope.row.item2">{{scope.row.item2 || ''}}</span>
                      <el-input v-else v-model="currentRow.item2" placeholder="请输入商业数量"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center" width="150">
                    <template slot-scope="scope">
                      <el-button @click="deteleRow(scope.row,scope.$index)" type="text" size="small">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </div> 
      </el-form>
      <div class="btn-container">
        <el-button class="jx-btn" type="warning" @click="boo.showDialog = false">取消</el-button>
        <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow('form')">确定</el-button>
      </div>
    </div>
    <!-- 选择产品 -->
    <el-dialog  :visible.sync="boo.showDialog" class="jx-dialog" width="75%">
      <div slot="title" class="header-title">
        <span class="title-name">添加产品</span>
      </div>
      <div class="jx-detail" style="padding: 0;">
        <div class="detail-item">
          <div class="item">
            <div class="select-type">
              <div class="item table-item" style="margin: 0;">
                <div class="right" style="padding: 0;">
                  <div class="item-inline">
                    <span>搜索商品：</span>
                    <el-input class="tel-value" v-model="params_product.name" placeholder="请输入商品名称"></el-input>
                  </div>
                  <div class="item-inline">
                    <el-button class="jx-btn" type="primary" @click="search_product">搜索</el-button>
                  </div>
                </div>
              </div>
            </div>
            <div class="jx-table">
              <el-table :data="shoplist" border style="width: 100%" v-loading="boo.loading">
                <el-table-column type="index" label="序列" width="55" align="center">
                  <template slot-scope="scope">
                    <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="img" label="产品图片" width="130" align="center">
                  <template slot-scope="scope">
                    <img class="logo" :src="scope.row.img"/>
                  </template>
                </el-table-column>
                <el-table-column prop="name" label="产品名称" width="180" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="address" label="适用地区" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="shop" label="支持门店" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="操作" width="90" align="center">
                  <template slot-scope="scope">
                    <el-button @click="hiddenRow(scope.row)" type="text" size="small">选择</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div v-if="shoplist.length != 0" class="jx-pagination">
                <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
                  :total="other.allRow">
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
        <div class="btn-container">
          <el-button class="jx-btn" type="warning" @click="boo.showDialog = false">取消</el-button>
          <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow_pro">确定</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 适用地区 -->
    <el-dialog  :visible.sync="boo.showDetail" class="jx-dialog" width="75%">
      <div slot="title" class="header-title">
        <span class="title-name">选择地区</span>
      </div>
      <div class="jx-detail">
        <div class="detail-item">
          <div class="item">
            <el-radio-group v-model="params_adres.radio" @change="getActive">
              <el-radio :label="1">不限地区</el-radio>
              <el-radio :label="2">适用地区</el-radio>
            </el-radio-group>
            <div class="active-item" v-if="boo.isAddress">
              <div class="select-type">
                <div class="item">
                  <span>搜索地区：</span>
                  <div class="right">
                    <div class="item-inline">
                      <el-input class="tel-value" v-model="params_adres.address" placeholder="请输入地区"></el-input>
                    </div>
                    <div class="item-inline">
                      <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
                    </div>
                  </div>
                </div>
                <div class="item" style="margin-bottom: 30px;">
                  <span>快速直达：</span>
                  <div class="right">
                    <span v-for="(item, index) in typelist" :key="index" :class="params_adres.type == item.val ? 'active' : ''" @click="selected(item)">{{item.label}}</span>
                  </div>
                </div>
                <div class="item">
                  <span>省份：</span>
                  <div class="right">
                    <el-checkbox :indeterminate="params_adres.isIndeterminate" v-model="params_adres.checkAll" @change="handleCheckAllChange">安徽省</el-checkbox>
                  </div>
                </div>
                <div class="item">
                  <span>市：</span>
                  <div class="right">
                    <el-checkbox-group v-model="params_adres.checkedCities" @change="handleCheckedCitiesChange">
                      <el-checkbox v-for="(item,index) in params_adres.cities" :key="index" :label="item.val">{{item.label}}</el-checkbox>
                    </el-checkbox-group>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="btn-container">
          <el-button class="jx-btn" type="warning" @click="boo.showDetail = false">取消</el-button>
          <el-button class="jx-btn" type="primary" :loading="boo.address_save" @click="submitRow_address">确定</el-button>
        </div>
      </div>
    </el-dialog>
	</div>
</template>

<script>
  import shoplist from 'static/json/product/shoplist.json'
  const detail = [
    {item1: '赠送',item2: '1',item3: '不限地区',item4: '200.00'}
  ]
  const typelist = [
    {label: 'A',val: '1'},{label: 'B',val: '2'},{label: 'C',val: '3'},
    {label: 'D',val: '4'},{label: 'E',val: '5'},{label: 'F',val: '6'},
    {label: 'G',val: '7'},{label: 'H',val: '8'},{label: 'I',val: '9'},
    {label: 'J',val: '10'},{label: 'K',val: '11'},{label: 'L',val: '12'},
    {label: 'M',val: '13'},{label: 'N',val: '14'},{label: 'O',val: '15'},
    {label: 'P',val: '16'},{label: 'Q',val: '17'},{label: 'R',val: '18'},
    {label: 'S',val: '19'},{label: 'T',val: '20'},{label: 'U',val: '21'},
    {label: 'V',val: '22'},{label: 'W',val: '23'},{label: 'X',val: '24'},
    {label: 'Y',val: '25'},{label: 'Z',val: '26'}
  ]
  const cityOptions = [
    {label: '合肥',val: '1'},{label: '芜湖',val: '2'},{label: '安庆',val: '3'},
  ]
	export default {
		data() {
			return {
        https: this.$api.order.quick,
        boo: {
          loading: false,
          showDialog: false,
          showDetail: false,
          saveing: false,
          address_save: false,
          product_save: false,
          isAddproduct: false,
          isAddress: false, // 选择地区
        },
        headers: {
          'access-token': localStorage.getItem('ms_token') || ''
        },
        params_list: {
          page: 1,
          size: 10,
          name: '',
          tel: '',
          cpno: '',
          start: '',
          end: '',
          type: '',
          bxtype: '',
          no: '',
          syno: '',
          address: '',
        },
        other: {
          allRow: 1,
          item2: '0',
          item4: '0',
        },
        shoplist: shoplist,
        params_product: {
          page: 1,
          size: 10,
          name: '',
        },
        params_adres: {
          radio: '',
          address: '',
          type: '',
          name: '不限',
          checkAll: false,
          checkedCities: [],
          cities: cityOptions,
          isIndeterminate: true
        },
        typelist: typelist, //快速直达
        rules: {
          item2: [{ required: true, message: '请输入商户户端APP名称', trigger: 'blur' }],
          name: [{ required: true, message: '请输入客户端APP名称', trigger: 'blur' }],
          item4: [{ required: true, message: '请输入客户电话', trigger: 'blur' }],
          item5: [{ required: true, message: '请输入首页介绍', trigger: 'blur' }],
          item6: [{ required: true, message: '请输入链接', trigger: 'blur' }],
        },
        detail: detail,
        currentRow: {},
			}
		},
		mounted(){
      let _self = this
      _self.getList()
    },
		methods: {
      getList(){},
      addRow(){
        let _self = this
        _self.detail.push({
          item1: '',item2: '',item3: '',item4: ''
        })
      },
      deteleRow(item,index){
        let _self = this
        _self.detail.splice(index,1)
      },
      getSum(param){
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          switch(column.property) {
            case "item2":
              sums[index] = this.other.item2
              break;
            default:
              break;
          }
        });
        return sums;
      },
      viewRow(){
        let _self = this
        _self.boo.showDialog = true
        // _self.currentRow = JSON.parse(JSON.stringify(item))
        _self.currentRow = {}
      },
      search_product(){
        
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      hiddenRow(){

      },
      submitRow_pro(){
        let _self = this
        _self.currentRow.item1 = '赠送' 
        _self.boo.showDialog = false
      },
      getActive(){
        let _self = this
        if(_self.params_adres.radio == 2){
          _self.boo.isAddress = true
        }else {
          _self.boo.isAddress = false
        }
      },
      viewAddress(){
        let _self = this
        _self.boo.showDetail = true
        if(_self.params_adres.name == '不限'){
          return _self.params_adres.radio = 1
        }else {
          return _self.params_adres.radio = 2
        }
      },
      selected(item){
        let _self = this
        _self.params_adres.type = item.val
      },
      handleCheckAllChange(val) {
        let _self = this                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        let arr = []
        _self.params_adres.cities.forEach(item => {
          arr.push(item.val)
        })
        _self.params_adres.checkedCities = val ? arr : [];
        _self.params_adres.isIndeterminate = false;
      },
      handleCheckedCitiesChange(value) {
        let _self = this
        let checkedCount = value.length;
        _self.params_adres.checkAll = checkedCount === _self.params_adres.cities.length;
        _self.params_adres.isIndeterminate = checkedCount > 0 && checkedCount < _self.params_adres.cities.length;
      },
      submitRow_address(){

      },
      submitRow(formName){
        let _self = this
				this.$refs[formName].validate((vaild)=>{
					if(vaild){  
            // _self.boo.saveing = true
            // let params = {
            // }    
            // let success = (res)=>{
            //   res = res.data
            //   if(res.status == 200){
            //     _self.getList()
            //   }else{
            //     _self.$message.error(res.message)
            //   }
            //   _self.boo.saveing = false
            //   _self.boo.showDialog = false
            // }
            // _self.$axios.post(_self.https.checked, params, success)   
					}else{
						return false
					}
				})
      }
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 78px
  .jx-table
    /deep/ .el-table__body td
      .cell
        height: auto
        line-height: auto
  /deep/ .jx-dialog .el-dialog__body
    padding: 20px 20px
  .active-item
    margin: 20px auto 0
    padding: 10px
    .select-type .item
      margin-bottom: 10px
    .select-type .item .right span
      padding: 0
      margin-right: 12px
      font-size: 17px
    .select-type .item .right span.active
      color: #333
      border: 0
      background: #fff
      font-size: 18px
      font-weight: 600
    .select-type 
      .jx-btn.el-button
        height: 32px !important
        line-height: 32px !important
      .jx-btn.el-button /deep/ span
        color: #fff
        line-height: 32px
        padding: 0 5px
        margin: 0
      /deep/ .el-checkbox__inner
        width: 14px
        padding: 0
        margin-right: 0
      /deep/ .el-checkbox__input
        padding: 0
        margin-right: 0
      /deep/ .el-checkbox__label
        padding: 0
        padding-left: 10px
        margin-right: 0
</style>
